﻿#include "MsgQueueTest.h"

using namespace SystemTool::Buffer;

struct MyQueueStr
{
	int iAge;

	std::string strMsg;
};

int TestMsgQueue()
{
	MessageQueue MyQueue;

	MyQueue.Configure("MyQueuedMemory", 1024, sizeof(MyQueueStr));

	if (!MyQueue.IsOpen())
	{
		MyQueue.Open(MQ_CREATE_ONLY);
	}

	{
		MyQueueStr mydata;

		mydata.iAge = 27;

		mydata.strMsg = "fhskfhkshffshfjkl";

		MyQueue.Write(&mydata);

		MyQueue.Close();
	}

	MessageQueue MyQueue2;

	MyQueue2.Configure("MyQueuedMemory", 1024, sizeof(MyQueueStr));

	if (!MyQueue2.IsOpen())
	{
		MyQueue2.Open(MQ_OPEN_ONLY);
	}

	MyQueueStr mydata2;

	MyQueue2.Read(&mydata2);

	MyQueue2.Close();

	std::cout << "I get data from queue1 is:" << mydata2.strMsg << std::endl;

	return 0;
}
